package com.lagou.guavacache.controller;

import com.lagou.guavacache.dto.ModifyPostDTO;
import com.lagou.guavacache.service.PostService;
import com.lagou.guavacache.util.SimpleResponseEntity;
import com.lagou.guavacache.vo.PostInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class PostController {

    @Autowired
    private PostService postService;

    @GetMapping("posts/hot")
    public ResponseEntity<List<PostInfoVO>> getHotPosts(@RequestParam Integer count) {
        return SimpleResponseEntity.get(postService.getHotPosts(count));
    }

    @GetMapping("posts/{postId}")
    public ResponseEntity<PostInfoVO> getPostById(@PathVariable String postId) {
        return SimpleResponseEntity.get(postService.getPostById(postId));
    }

    @PutMapping("posts/{postId}")
    public ResponseEntity<PostInfoVO> modifyPostById(@PathVariable String postId,
                                                     @RequestBody ModifyPostDTO modifyPostDTO) {
        postService.modifyPostById(postId, modifyPostDTO);
        return SimpleResponseEntity.put();
    }
}
